package com.ptszyxx.popose.module.main.dynamic.adapter;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.databinding.ItemDynamicCommentBinding;
import com.ptszyxx.popose.module.main.dynamic.vm.DynamicCommentVM;
import com.ysg.http.data.entity.dynamic.CommentEntity;
import com.ysg.utils.YRecyclerViewUtil;

public class DynamicCommentAdapter extends BaseQuickAdapter<CommentEntity, BaseDataBindingHolder<ItemDynamicCommentBinding>> {

    private DynamicCommentVM viewModel;
    private Presenter mPresenter = new Presenter();

    public DynamicCommentAdapter(DynamicCommentVM viewModel) {
        super(R.layout.item_dynamic_comment);
        this.viewModel = viewModel;
    }

    @Override
    protected void convert(BaseDataBindingHolder<ItemDynamicCommentBinding> holder, CommentEntity item) {
        ItemDynamicCommentBinding binding = holder.getDataBinding();
        if (binding != null) {
            binding.setEntity(item);
            binding.setViewModel(viewModel);
            binding.setPresenter(mPresenter);
            binding.setPosition(holder.getBindingAdapterPosition());
            binding.executePendingBindings();

            //回复
            int replyCount = item.getHfcount();
            if (replyCount > 0) {
                String replyNum = String.format(getContext().getResources().getString(R.string.dynamic_reply_num), ""+ replyCount);
                binding.tvReplyNum.setText(replyNum);
                binding.tvReplyNum.setVisibility(View.VISIBLE);
                if (replyCount > 3) {
                    binding.tvReplyNum.setText(getContext().getResources().getString(R.string.dynamic_look_more));
                }
                binding.viewReply.setVisibility(View.VISIBLE);
            } else {
                binding.tvReplyNum.setVisibility(View.GONE);
                binding.viewReply.setVisibility(View.GONE);
            }
            //回复列表
            DynamicCommentReplyAdapter adapter = new DynamicCommentReplyAdapter(viewModel);
            YRecyclerViewUtil.initNoLine(getContext(), binding.recyclerViewReply, adapter);
            adapter.setList(item.getHfList());

        }
    }

    public static class Presenter{
        public void onAvatarClick(DynamicCommentVM viewModel, CommentEntity entity){
            //用户详情
            viewModel.jumpUserDetail(entity);
        }
        public void onLikeClick(DynamicCommentVM viewModel, CommentEntity entity, int position){
            viewModel.onCommentLikeClick(entity, position);
        }
        public void onReplyClick(DynamicCommentVM viewModel, CommentEntity entity, int position){
            viewModel.onReplyClick(entity, position);
        }
        public void onJumpReplyClick(DynamicCommentVM viewModel, CommentEntity entity){
            viewModel.jumpDynamicReply(entity);
        }
    }








}
